package com.qidian.mes.md.controller;

import com.qidian.mes.md.service.UnitService;
import com.qidian.mes.pojo.Unit;
import com.qidian.mes.util.pojo.QdResult;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.swing.*;

/**
 * @Author: 小可怎么都睡不够
 * @Description:
 * @Time: 2024-04-07 14:57
 **/

@RestController
@RequestMapping("/unit")
@CrossOrigin
public class UnitController {
    @Autowired
    UnitService unitService;

    /**
     * @Author: 小可怎么都睡不够
     * @Date: 7/4/2024
     * @Description: 获取所有单位数据
     * @Name: findAll
     * @return: com.qidian.mes.util.pojo.QdResult
     */
    @GetMapping("/query/{page}/{limit}")
    public QdResult findAll(@PathVariable Integer page, @PathVariable Integer limit) {
        return unitService.findAll(page,limit);
    }

    @GetMapping("/queryAll")
    public QdResult noPagesFindAll(){
        return unitService.noPagesFindAll();
    }

    @GetMapping("/query/{name}/{page}/{limit}")
    public QdResult findByName(@PathVariable("name") String name,@PathVariable Integer page,@PathVariable Integer limit) {
        return unitService.findByName(name,page,limit);
    }
    @PostMapping("/add")
    public QdResult add(@RequestBody Unit unit) {
        return unitService.add(unit);
    }

    /**
     * @Author: 小可怎么都睡不够
     * @Date: 7/4/2024
     * @Description:  修改单位状态
     * @Name: udpateUnitStatus
     * @param id
     * @param status
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @PutMapping("/update/status")
    private QdResult udpateUnitStatus(@RequestParam Integer id,@RequestParam Integer status){
        return unitService.updateStatus(id,status);
    }

    @PutMapping("/update")
    private QdResult update(@RequestBody Unit unit){
        return unitService.update(unit);
    }

    @GetMapping("/query/count")
    public QdResult getCount(){
        return unitService.getCount();
    }
}
